import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getx_scaffold/getx_scaffold.dart';
import 'package:oramemo/entity/voice_record_entity.dart';
import 'package:oramemo/pages/first/first_router.dart';
import 'package:oramemo/pages/transcription/ai_transcription/ai_transcription_logic.dart';
import 'package:oramemo/pages/transcription/transcription_router.dart';
import 'package:oramemo/widget/my_refresh.dart';
import 'model.dart';
import 'msg_logic.dart';
import 'widgets/message_card.dart';

class MsgPage extends StatelessWidget {
  const MsgPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetBuilder<MsgLogic>(
      init: MsgLogic(),
      builder: (logic) {
        return MyRefresh(
          onRefresh: () {
            logic.load();
          },
          onLoad: () {
            logic.requestData(page: logic.page + 1);
          },
          child: ListView.builder(
            padding: EdgeInsets.symmetric(vertical: 15.h),
            itemCount: logic.list.length,
            itemBuilder: (context, index) {
              final data = logic.list[index];
              return MessageCard(
                message: data,
                onTap: () {
                  Get.toNamed(FirstRouter.msgDetailPage,
                      arguments: data);
                  logic.markAsRead(data);
                },
              );
            },
          ),
        );
      },
    );
  }
}
